<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>主从配置</title>
    {template 'stourtravel/public/public_min_js'}
    {php echo Common::getCss('style.css,base.css,base_new.css'); }
    {php echo Common::getScript('config.js');}
</head>
<body>

	<table class="content-tab">
        <tr>
            <td width="119px" class="content-lt-td"  valign="top">
                {template 'stourtravel/public/leftnav'}
                <!--右侧内容区-->
            </td>
            <td valign="top" class="content-rt-td">
                <form id="configfrm">
                    <div class="w-set-con">
                    	<div class="cfg-header-bar">
                            <div class="cfg-header-tab">
                                <span class="item on">数据库主从配置<img class="ml-5" style="cursor:pointer; vertical-align: middle; margin-top: -3px;" title="查看帮助cfg_slave_config" src="/newtravel/public/images/help-ico.png" onclick="ST.Util.helpBox(this,'cfg_slave_config',event)"></span>
                            </div>
                    		<a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
                    	</div>
        
                        <div class="w-set-nr">
                            <ul class="info-item-block">
                                <li>
                                    <span class="item-hd">是否启用</span>
                                    <div class="item-bd">
                                        <label class="radio-label ml-20"><input type="radio" name="cfg_slave_open" value="1" {if $config['cfg_slave_open']==1}checked{/if}>开启</label>
                                        <label class="radio-label ml-20"><input type="radio" name="cfg_slave_open" value="0" {if $config['cfg_slave_open']==0}checked{/if}>关闭</label>
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">从库IP：</span>
                                    <div class="item-bd">
                                        <input type="text" name="cfg_slave_dbhost" id="cfg_slave_dbhost" class="input-text w300" value="{$config['cfg_slave_dbhost']}" placeholder="如116.15.16.25" >
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">从库名称：</span>
                                    <div class="item-bd">
                                        <input type="text" name="cfg_slave_dbname" id="cfg_uc_ip" class="input-text w300" value="{$config['cfg_slave_dbname']}" placeholder="如stourwebcms" >
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">从库用户：</span>
                                    <div class="item-bd">
                                        <input type="text" name="cfg_slave_dbuser" id="cfg_slave_dbuser" class="input-text w300" value="{$config['cfg_slave_dbuser']}" placeholder="如root" autocomplete="off" >
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">从库密码：</span>
                                    <div class="item-bd">
                                        <input type="text" name="cfg_slave_dbpwd" id="cfg_uc_dbprefix" class="input-text w300" value="{$config['cfg_slave_dbpwd']}" autocomplete="off" >
                                    </div>
                                </li>
                            </ul>

                            <div class="clear clearfix mt-20">
                                <a class="btn btn-primary radius size-L ml-115" href="javascript:;" id="btn_save">保存</a>
                                <!-- <a class="cancel" href="#">取消</a>-->
                                <input type="hidden" name="webid" id="webid" value="0">
                            </div>

                        </div>
                    </div>
                </form>

            </td>
        </tr>
    </table>

	<script>

	$(document).ready(function(){

        //配置信息保存
        $("#btn_save").click(function(){
            var openStatus = $("input[name='cfg_slave_open']:checked").val();
            if(openStatus == 1){
                ST.Util.confirmBox('重要提示', '设置开启从库后,所有读请求会从从库获取,确定已经配置好数据库主从同步功能,且从库可以正常连接?', function () {
                    configSave();
                })
            }else{
                configSave();
            }

        })
    });
	function configSave(){
        var url = SITEURL+"distribute/ajax_save_database";
        var frmdata = $("#configfrm").serialize();
        $.ajax({
            type:'POST',
            url:url,
            dataType:'json',
            data:frmdata,
            success:function(data){
                if(data.status){
                    ST.Util.showMsg('保存成功',4);
                }else{
                    ST.Util.showMsg(data.msg,5);
                }
            }
        })
    }
    </script>

</body>
</html>
